#!/bin/bash
#set -v

SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILDINFO=${BUILDINFO:-""}

# gather buildinfo if not already provided
# For a release build BUILDINFO should be produced
# at the beginning of the build and used throughout
if [[ -z ${BUILDINFO} ]];then
    BUILDINFO=$(mktemp)
    "${SCRIPTPATH}/report_build_info.sh" > "${BUILDINFO}"
fi

# BUILD LD_EXTRAFLAGS
LD_EXTRAFLAGS=""

while read -r line; do
    LD_EXTRAFLAGS="${LD_EXTRAFLAGS} -X ${line}"
done < "${BUILDINFO}"

set -v
go build \
	-ldflags=" ${LD_EXTRAFLAGS} "\
  	-o api-gateway ./cmd/main.go

cp api-gateway ./docker
cp -r proxy/rootfs/etc/ ./docker

